package com.opgea.crm.web.form;

import java.util.ArrayList;
import java.util.List;

import com.opgea.crm.domain.entities.Employee;
import com.opgea.crm.domain.entities.Employeeemails;
import com.opgea.crm.domain.entities.Employeephones;
import com.opgea.crm.domain.entities.security.CrmUser;
import com.opgea.crm.domain.entities.security.Group;

public class UserPersonalInfoForm {
	
	private Long userId;
	private Long employeeId;

	private String firstName;
	private String middleInitial;
	private String lastName;
	private String title;
	private String empCode;
	private String email;
	private String phone1;
	private String phone2;
	private String phone3;
	private String phone4;
	private String employeeType;
	
	private String userName;
	private String password;
	private String confirmPassword;
	private String reminder;
	private String permission;
	private Long permissionId;
	
	
	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Long getUserId(){
		return userId;
	}
	
	
	

	public Long getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(Long employeeId) {
		this.employeeId = employeeId;
	}

	
	public void setFirstName(String firstName){
		this.firstName =firstName;
	}
	
	public String getFirstName(){
		return firstName;
	}
	
	public void setMiddleInitial(String middleInitial){
		this.middleInitial = middleInitial;
	}
	
	public String getMiddleInitial(){
		return middleInitial;
	}
	
	public void setLastName(String lastName){
		this.lastName= lastName;
	}
	
	public String getLastName(){
		return lastName;
	}
	
	public void setTitle(String title){
		this.title= title;
	}
	
	public String getTitle(){
		return title;
	}
	
	public void setEmpCode(String empCode){
		this.empCode= empCode;
	}
	
	public String getEmpCode(){
		return empCode;
	}
	
	public void setEmail(String email){
		this.email= email;
	}
	
	public String getEmail(){
		return email;
	}
	
	public void setPhone1(String phone1){
		this.phone1=phone1;
	}
	
	public String getPhone1(){
		return phone1;
	}
	
	public void setPhone2(String phone2){
		this.phone2=phone2;
	}
	
	public String getPhone2(){
		return phone2;
	}
	
	

	public String getPhone3() {
		return phone3;
	}

	public void setPhone3(String phone3) {
		this.phone3 = phone3;
	}

	public String getPhone4() {
		return phone4;
	}

	public void setPhone4(String phone4) {
		this.phone4 = phone4;
	}
	
	

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public String getReminder() {
		return reminder;
	}

	public void setReminder(String reminder) {
		this.reminder = reminder;
	}

	public void setEmployeeType(String employeeType) {
		this.employeeType = employeeType;
	}

	public String getEmployeeType() {
		return employeeType;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public String getPermission() {
		return permission;
	}

	public void setPermissionId(Long permissionId) {
		this.permissionId = permissionId;
	}

	public Long getPermissionId() {
		return permissionId;
	}

	public UserPersonalInfoForm(){}
	
	public UserPersonalInfoForm(Employee emp){
		List<Employeeemails> emailList = new ArrayList<Employeeemails>(emp.getEmployeeemailsCollection());
		List<Employeephones> phoneList = new ArrayList<Employeephones>(emp.getEmployeephonesCollection());
		CrmUser user = emp.getUser();
		
		this.setEmployeeId(emp.getId());
		this.setFirstName(emp.getFirstName());
		this.setMiddleInitial(emp.getMiddleInitial());
		this.setLastName(emp.getLastName());
		this.setEmpCode(emp.getEmpCode());
		this.setTitle(emp.getTitle());
		if(emailList != null){
			this.setEmail(emailList.get(0).getAddress());
		}
		if(phoneList != null){
			if(phoneList.get(0) != null){
				this.setPhone1(phoneList.get(0).getPhoneNo());
			}
			if(phoneList.get(1) != null){
				this.setPhone2(phoneList.get(1).getPhoneNo());
			}
			if(phoneList.get(2) != null){
				this.setPhone3(phoneList.get(2).getPhoneNo());
			}
			if(phoneList.get(3) != null){
				this.setPhone4(phoneList.get(3).getPhoneNo());
			}
	    }
		if(user != null){
			this.setUserName(user.getUserName());
			this.setPassword(user.getPassword());
			this.setConfirmPassword(user.getPassword());
			Group group = user.getGroups().get(0);
			this.setPermission(group.getName());
			this.setPermissionId(group.getId());
		}
	}
}
